from typing import List, Tuple, Optional
from multiprocessing import Process

from .scraper import TrackShipmentsScraper
from utils import (
    get_links_for_parsing,
    get_random_account
)


def main() -> None:

    previous_account: Optional[Tuple[str, str]] = None
    processes: List[Process] = []
    links_for_parsing: List[str] = get_links_for_parsing()

    for link_for_parsing in links_for_parsing:
        account: Tuple[str, str] = get_random_account(previous_account)
        process: Process = Process(
            target=TrackShipmentsScraper().start,
            args=(link_for_parsing, account)
        )
        processes.append(process)
        previous_account = account

    for process in processes:
        process.start()

    for process in processes:
        process.join()
